#!/bin/bash

# 这个是项目打包脚本

rm -rf target/*
# 构建
./gradlew bootJar

SpringBootPluginVersion=`cat src/main/resources/SpringBootPluginSystem.properties | grep springbootplugin.version | awk -F'=' '{print $2}'`

echo $SpringBootPluginVersion

cd target
# 解压jar
jar -xf SpringBootPlugin-${SpringBootPluginVersion}.jar
mv META-INF/MANIFEST.MF META-INF/MANIFEST.MF2

jar -xf BOOT-INF/lib/sbp_remap.jar
rm -f BOOT-INF/lib/sbp_remap.jar

jar -xf BOOT-INF/lib/asm-commons-*
rm -f BOOT-INF/lib/asm-commons-*

jar -xf BOOT-INF/lib/sbp_bukkit.jar
rm -f BOOT-INF/lib/sbp_bukkit.jar

jar -xf BOOT-INF/lib/slf4j-api-*
rm -f BOOT-INF/lib/slf4j-api-*

rm -f META-INF/MANIFEST.MF
mv META-INF/MANIFEST.MF2 META-INF/MANIFEST.MF
# 拷贝类文件到根目录
cp -R BOOT-INF/classes/* .
# 删除已拷贝的文件
rm -rf BOOT-INF/classes/*
# 入口类需要由SpringBoot来加载,所以将其拷贝到BOOT-INF/classes
mkdir -p BOOT-INF/classes/lol/clann/minecraft/springboot
mv lol/clann/minecraft/springboot/Main.class BOOT-INF/classes/lol/clann/minecraft/springboot/Main.class
mv application.properties BOOT-INF/classes
# 拷贝资源文件
cp -R sbp BOOT-INF/classes
rm -rf sbp
# 重新打包jar
jar -c0fm SpringBootPlugin-${SpringBootPluginVersion}.jar META-INF/MANIFEST.MF META-INF relocate org BOOT-INF lol plugin.yml SpringBootPluginSystem.properties


cp SpringBootPlugin-${SpringBootPluginVersion}.jar ~/public/SpringBootPlugin-${SpringBootPluginVersion}.jar